package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LCJZOF63 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int maxProfit(int[] prices) {
            if (null == prices || prices.length <= 1) return 0;

            int curMin = prices[0], res = 0;
            for (int i = 1; i < prices.length; i++) {
                curMin = Math.min(curMin, prices[i]);
                res = Math.max(res, prices[i] - curMin);
            }

            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[7,6,4,3,1]");
        System.out.println(solution.maxProfit(arr));
    }

    public static void main(String[] args) throws Exception {
        LCJZOF63 an = new LCJZOF63();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
